package org.arclib.x.light;

import java.util.ArrayList;

import org.arclib.math.Point;
import org.lwjgl.opengl.GL11;

/**
 * Umbrae are the regions of full shadow behind light blockers.
 * 
 * Represented by a series of lines.
 **/
public class Umbra
{
	ArrayList<Section> sections;

	void draw()
	{
		assert (sections.size() >= 2);

		int style = GL11.GL_TRIANGLE_STRIP;
		// auto style = GL_LINES;

		// the umbra draw regions (if considered quads) can sometimes
		// be concave, so use triangles and start once from left and
		// once from right to minimize problems

		GL11.glBegin(style);
		for (int i = 0; i < sections.size() / 2 + 1; i++)
		{
			GL11.glVertex2d(sections.get(i).base.x, sections.get(i).base.y);
			Point p = sections.get(i).base.add(sections.get(i).direction);
			GL11.glVertex2d(p.x, p.y);
		}
		GL11.glEnd();

		GL11.glBegin(style);
		for (int i = sections.size(); i > sections.size() / 2; i--)
		{
			GL11.glVertex2d(sections.get(i).base.x, sections.get(i).base.y);
			Point p = sections.get(i).base.add(sections.get(i).direction);
			GL11.glVertex2d(p.x, p.y);
		}
		GL11.glEnd();
	}
}
